package com.chezai.client.widget;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chezai.client.R;
import com.chezai.client.global.Const;

import butterknife.BindView;

/**
 * 登录方式Dialog
 * Created by likunyang on 2017/8/2.
 */

public class LoginTypeDialog extends BaseDialog implements View.OnClickListener {
    @BindView(R.id.image_id_card)
    ImageView imageIdCard;
    @BindView(R.id.image_app)
    ImageView imageApp;
    @BindView(R.id.image_vert)
    ImageView imageVert;
    @BindView(R.id.image_rfid)
    ImageView imageRfid;
    @BindView(R.id.image_face)
    ImageView imageFace;
    @BindView(R.id.dialog_normal_title)
    TextView tvTitle;
    private OnLoginTypeClickListener listener;

    public LoginTypeDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected int getDialogLayoutResId() {
        return R.layout.dialog_login_type;
    }

    @Override
    protected void initView(Context context) {
    }

    @Override
    protected float getwScale() {
        return 0.88f;
    }

    @Override
    protected float gethScale() {
        return 0.8f;
    }

    @Override
    protected int getGravity() {
        return Gravity.CENTER;
    }

    @Override
    protected void setListener() {
        imageIdCard.setOnClickListener(this);
        imageApp.setOnClickListener(this);
        imageVert.setOnClickListener(this);
        imageRfid.setOnClickListener(this);
        imageFace.setOnClickListener(this);
    }

    public void setTitle(String title) {
        if (tvTitle != null) {
            tvTitle.setText(title);
        }
    }

    /**
     * 设置登录类型
     *
     * @param bytes
     */
    public void setLoginType(byte[] bytes) {
        imageRfid.setVisibility(1 == bytes[0] ? View.VISIBLE : View.GONE);
        imageApp.setVisibility(1 == bytes[1] ? View.VISIBLE : View.GONE);
        imageIdCard.setVisibility(1 == bytes[2] ? View.VISIBLE : View.GONE);
        imageFace.setVisibility(1 == bytes[3] ? View.VISIBLE : View.GONE);
        imageVert.setVisibility(1 == bytes[4] ? View.VISIBLE : View.GONE);
    }

    /**
     * 设置点击登录类型listener
     *
     * @param listener
     */
    public void setOnLoginTypeClickListener(OnLoginTypeClickListener listener) {
        this.listener = listener;
    }

    /**
     * 1：指纹；2：二维码；3：声纹；4：人脸图像 5：微信二维码 6：RFID卡 7：验证码 8:身份证
     *
     * @param v
     */
    @Override
    public void onClick(View v) {
        if (listener != null) {
            short type = Const.LOGIN_TYPE_APP;
            switch (v.getId()) {
                case R.id.image_rfid://RFID
                    type = Const.LOGIN_TYPE_RFID;
                    break;
                case R.id.image_app://app二维码
                    type = Const.LOGIN_TYPE_APP;
                    break;
                case R.id.image_id_card://身份证
                    type = Const.LOGIN_TYPE_IDCARD;
                    break;
                case R.id.image_face://人脸识别
                    type = Const.LOGIN_TYPE_FACE;
                    break;
                case R.id.image_vert://验证码
                    type = Const.LOGIN_TYPE_VERT;
                    break;
//                case R.id.image_wx://微信二维码
//                    type = Const.LOGIN_TYPE_WX;
//                    break;
            }
            listener.onLoginTypeClick(this, v, type);
        }
    }

    public void isSign(boolean isSign) {
        if (isSign) {
            tvTitle.setText("请选择登录方式");
        } else {
            tvTitle.setText("请选择登出方式");
        }
    }

    public interface OnLoginTypeClickListener {
        void onLoginTypeClick(Dialog dialog, View v, short loginType);
    }
}
